package fr.grobim.hangovers.gestionBudget.daos.factures.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import fr.grobim.hangovers.gestionBudget.beans.factures.ReglementFacture;
import fr.grobim.hangovers.gestionBudget.daos.factures.ReglementFactureDao;
import fr.grobim.hangovers.gestionBudget.daos.impl.AbstractDaoImpl;

@Repository
public class ReglementFactureDaoImpl extends AbstractDaoImpl<ReglementFacture, Integer> implements ReglementFactureDao {
	
	public ReglementFactureDaoImpl () {
		super(ReglementFacture.class);
	}
	
	private String requeteObtenirFactureParFacture = "From ReglementFacture rf Where rf.facture.id = :id Order by rf.datePayement DESC";
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ReglementFacture> obtenirReglementFactureParFacture(Integer id, Integer resultatsMax) {
		Query requeteHQL = creerQuery(requeteObtenirFactureParFacture).setInteger("id", id);
		if (resultatsMax != null) {
			requeteHQL.setMaxResults(resultatsMax);
		}
		return requeteHQL.list();
	}
	
}
